import { defineConfig, loadEnv } from "vite";
import vue from "@vitejs/plugin-vue";

// https://vite.dev/config/
export default defineConfig(({ mode }) => {
  const env = loadEnv(mode, process.cwd());
  return {
    plugins: [vue()],
    resolve: {
      alias: {
        // 配置src目录
        "@": "/src",
      },
    },
    server: {
      host: "0.0.0.0",
      port: 4000, // 端口号
      open: false, // 是否自动打开浏览器
      hmr: true,
      proxy: {
        [env.VITE_APP_BASE_API]: {
          // product http://123.56.10.225 账户：15911048920 密码：admin123
          // dev http://39.105.3.138:8080 账户：15911048920 密码：admin123
          target: "http://39.105.3.138:8080",
          changeOrigin: true,
          ws: true,
          rewrite: (path) =>
            path.replace(new RegExp("^" + env.VITE_APP_BASE_API), ""),
        },
      },
    },
  };
});
